<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8" />
    <title>index</title>
</head>

<body>
    <button id="code">扫描</button>
    <button id="order">下单</button>
    <script>
        const code = document.getElementById('code')
        const order = document.getElementById('order')
        let ws;
        code.onclick = function () {
            // 和后台ws服务建立链接
            ws = new WebSocket('ws://localhost:3000')
        }
        order.onclick = function () {
            // 客户端向服务器端发送数据
            ws.send('小鸡炖蘑菇')
            ws.onmessage = function (data) {
                console.log(data)
            }
        }

    </script>
</body>

</html>